 <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.css">
    <link rel="stylesheet" href="../plugins/css/index.css">
    <script src="../../../plugins/js/request.js"></script>
    <script src="../../../plugins/js/jquery-3.3.1.js"></script>
    <script type="text/javascript" src="../plugins/js/index/api.js"></script>
    <script type="text/javascript" src="../plugins/js/index/getblog.js"></script>
    <title>首页</title>
</head>
<body >
<div id="Blog">


<!-- 导航 -->
<nav class="ui inverted attached segment m-padded-tb-mini m-shadow-small">
    <div class="ui container">
        <div class="ui inverted secondary stackable menu">
            <h2 class="ui teal header item">Blog</h2>
            <a href="index.html" class="m-item item m-mobile-hide"><i class="home icon"></i> 首页</a>
            <a href="types.html" class="m-item item m-mobile-hide"><i class="idea icon"></i>分类</a>
            <a href="tags.html" class="m-item item m-mobile-hide"><i class="tags icon"></i>标签</a>
            <a href="archives.html" class="m-item item m-mobile-hide"><i class="clone icon"></i>归档</a>
            <a href="about.html" class="m-item item m-mobile-hide"><i class="info icon"></i>关于我</a>
            <div class=" m-item right item m-mobile-hide">
                <div class="ui icon  input">
                    <input type="text" placeholder="搜索.......">
                    <i class="search link icon"></i>
                </div>
            </div>
        </div>
    </div>
    <a href="#" class="ui menu toggle black icon button m-top-right m-mobile-show">
        <i class="sidebar icon"></i>
    </a>
</nav>

<!-- 内容 -->
<div class="m-padded-tb-large">
    <div class="ui container" >
        <div class="ui stackable grid">
            <!-- 左边博客列表 -->
            <div class="eleven wide column">
                <!-- header -->
                <div class="ui top attached segment">
                    <div class="ui middle aligned two column grid">
                        <div class="column">
                            <h3 class="ui teal header">博客</h3>
                        </div>
                        <div class="right aligned column">
                            共 <h2 class="ui orange header m-inline-block">{{totals}}</h2> 篇
                        </div>
                    </div>
                </div>
                <!-- content -->
                <div class="ui attached  segment" v-for="(item,index) in blog">
                    <div class="ui padded vertical segment m-padded-tb-big">
                        <div class="ui mobile reversed stackable grid">
                            <div class="eleven wide column">
                                <h3 class="ui header">
                                    <a href="" target="_blank" class="m-black">{{item.title}}</a>
                                </h3>
                                <p class="m-text">{{item.description}}
                                </p>
                                <div class="ui grid">
                                    <div class="eleven wide column">
                                        <div class="ui  mini horizontal link list">
                                            <div class="item">
                                                <img :src="item.avatar" alt=""
                                                     class="ui avatar image">
                                                <div class="content">
                                                    <div class="header">{{item.name}}</div>
                                                </div>
                                            </div>
                                            <div class="item">
                                                <i class="calendar icon"></i> {{item.updateTime}}
                                            </div>
                                            <div class="item">
                                                <i class="eye icon"></i> {{item.views}}
                                            </div>
                                        </div>
                                    </div>
                                    <div class="right aligned five wide column">
                                        <a href="#" target="_blank"
                                           class="ui teal basic label m-padded-tiny m-text-thin">{{item.type}}</a>
                                    </div>
                                </div>
                            </div>
                            <div class="five wide column">
                                <a href="#" target="-blank">
                                    <img :src="item.firstPicture" alt="" class="ui rounded image">
                                </a>
                            </div>
                        </div>
                    </div>

                </div>
                <!-- footer -->
                <div class="ui bottom attached segment">
                    <div class="ui middle aligned two column grid">
                        <div class="column">
                            <a href="#" class="ui mini teal basic button">上一页</a>
                        </div>
                        <div class="right aligned column">
                            <a href="#" class="ui mini teal basic button">下一页</a>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 右边 top-->
            <div class="five wide column">
                <div class="ui segments">
                    <div class="ui secondary segment">
                        <div class="ui two column grid">
                            <div class="column"><i class="idea icon"></i> 分类</div>
                            <div class="right aligned column">
                                <a href="types.html">more <i class="angle double right icon"></i></a>
                            </div>
                        </div>
                    </div>
                    <!-- 分类 -->
                    <div class="ui teal segment">
                        <div class="ui fluid vertical menu" >
                            <a href="#" class="item" v-for="(item,index) in type" @click="jump(item.id)">
                                {{item.name}}
                                <div class="ui teal basic left pointing label ">{{item.count}}</div>
                            </a>

                        </div>

                    </div>
                </div>
                <!-- 标签 -->
                <div class="ui segments m-margin-top-large">
                    <div class="ui secondary segment">
                        <div class="ui two column grid">
                            <div class="column"><i class="tags icon"></i> 标签</div>
                            <div class="right aligned column">
                                <a href="#">more <i class="angle double right icon"></i></a>
                            </div>
                        </div>
                    </div>
                    <div class="ui teal segment">
                        <a href="#" target="_blank" class="ui teal basic left pointing label m-margin-tb-tiny" v-for="(item,index) in tag" @click="jumpTag(item.id)">
                            {{item.name}}
                            <div class="detail">{{item.count}}</div>
                        </a>
                    </div>
                </div>
                <!-- 最新推荐 -->
                <div class="ui segments m-margin-top-large">
                    <div class="ui secondary segment ">
                        <div class="column"><i class="bookmark icon"></i> 最新推荐</div>
                    </div>
                    <div class="ui segment" v-for="(item,index) in blog">
                            <a href="#" target="_blank" class="m-black">{{item.title}}</a>
                    </div>
                </div>

                <!-- 二维码 -->
                <h4 class="ui horizontal divider header m-margin-top-large">扫码关注我</h4>
                <div class="ui centered card" style="width: 11em;">
                    <img src="" alt="" class="ui rounded image">
                </div>
            </div>

        </div>
    </div>

</div>

<!-- 底部footer -->
<footer class="ui inverted vertical segment m-padded-tb-massive">
    <div class="ui center aligned container" >
        <div class="ui inverted divided stackable grid">
            <div class="three wide column">
                <img src="https://cdn.seovx.com/ha/?mom=302" class="ui rounded image" alt="" style="width: 120px;">
            </div>
            <div class="three wide column">
                <h4 class="ui inverted header">最新博客</h4>
                <div class="ui inverted link list"  v-for="(item,index) in blog.slice(0,3)">
                    <a href="#" class="item">{{item.title}}</a>
                </div>
            </div>
            <div class="three wide column">
                <h4 class="ui inverted header">最新博客</h4>
                <div class="ui inverted link list">
                    <a href="#" class="item">用户故事</a>
                    <a href="#" class="item">用户故事</a>
                    <a href="#" class="item">用户故事</a>
                </div>
            </div>
            <div class="seven wide column">
                <h4 class="ui inverted header">最新博客</h4>
                <p>一段内容</p>
            </div>
        </div>
        <div class="ui inverted section divider"></div>
        <p class="m-text-spaced m-text-lined">BV1nE411r7TF?p=4&spm_id_from=pageDriver&vd_s</p>
    </div>

</footer>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<!-- 官网提供的 axios 在线地址 -->
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.js"></script>
<script>
    $('.menu.toggle').click(function () {
        $('.m-item').toggleClass('m-mobile-hide');
    });


    new Vue({
        el:"#Blog",
        data() {
            return {
                page: 1,
                pageSize: 5,
                blog:[],
                type:[],
                tag:[],
                totals:'',


            }
        },
        created(){
            this.init()
            this. types()
        },
        methods:{
            //aixos 会返回一个Promise对象
            //async 和 await 基于 promise 的。
            //   使用 async 的函数将会始终返回一个 promise 对象
            //   await 关键字只能放到async 函数里面
            async init() {
                const params = {
                    page: this.page,
                    pageSize: this.pageSize,

                }

                await getBlog(params).then(res => {
                    console.log(res.data)
                    if (String(res.data.code) === '1') {
                        console.log(res.data.data.total)
                        this.totals=res.data.data.total
                        this.blog =res.data.data.records
                        console.log(this.blog)

                    }
                }).catch(err => {
                    alert("cuowu")
                })

            },
            async types(){
                const params = {
                    page: this.page,
                    pageSize: this.pageSize,

                }
                await Type(params).then(res => {
                    console.log(res.data)
                    if (String(res.data.code) === '1') {
                        this.type =res.data.data.records
                        console.log(this.type)

                    }
                }).catch(err => {
                    alert("cuowu")
                })

                await Tag(params).then(res => {
                    console.log(res.data)
                    if (String(res.data.code) === '1') {
                        this.tag =res.data.data.records
                        console.log(this.tag)

                    }
                }).catch(err => {
                    alert("cuowu")
                })
            },
            jump(id){
                window.location.href="types.html?id="+id;
            },
            jumpTag(id){
                window.location.href="tags.html?id="+id;
            }
        },

        })

</script>
</body>
</html>